import dayjs from 'dayjs'
import classnames from 'classnames'
import style from './index.module.css'

function Calendar({ date, setCurrentDate }) {
    const week = ['日', '一', '二', '三', '四', '五', '六']
    const showList = Array.from({ length: 7 }, (_, i) => i)
    return (
		<div style={{ padding: '12px 0' }}>
            <div className={style.title}>选择日期</div>
            <div className={style.weekTitle}>
				{showList.map(item => <div key={`weekTitle_${item}`} className={style.weekTitleItem}>{week[dayjs().add(item, 'day').day()]}</div>)}
			</div>
            
			<div className={style.weekItem}>
				{showList.map(item => (
					<div
						key={`weekTitle_${item}`}
						className={classnames(style.week_item, {
							[style.selected_week_item]: dayjs(date).date() === dayjs().add(item, 'day').date(),
						})}
                        onClick={() => setCurrentDate(dayjs().add(item, 'day'))}
					>
                        {dayjs().add(item, 'day').date()}
                    </ div>
				))}
			</div>
		</div>
	)
}

export default Calendar
